var fs = require('fs');
var path = require('path');
var nodeXlsx = require('node-xlsx').default;

// 下载到本地的词库
const localLib = require('./localization_en.json');
// 需要检查的小程序词库
const checkLib = require('./language.js').info;
// const checkLibDetail = require('./language-detail.js').info;
// const checkLibForm = require('./language-form.js').info;
// const checkLibList = require('./language-list.js').info;
// const checkLib = { ...checkLibDetail, ...checkLibForm, ...checkLibList };
// 匹配到的key
const notInWord = {};

for (const key in checkLib) {
  if (
    (localLib.ios[key] && localLib.android[key]) ||
    localLib.pre_object[key] ||
    localLib.option_set[key]
  )
    continue;
  
  const tags = [];
  if (!localLib.ios[key]) tags.push('ios');
  if (!localLib.android[key]) tags.push('android'); 
  notInWord[key] = [key, checkLib[key], tags.join(',')];
}

const excelData = [['key', 'zh_CN', 'tags']];
Object.values(notInWord).forEach(value => {
  excelData.push(value);
});
//由于各列数据长度不同，可以设置一下列宽
const options = {
  sheetOptions: { '!cols': [{ wch: 70 }, { wch: 70 }, { wch: 70 }] },
};
//生成表格
var buffer = nodeXlsx.build([{ name: 'sheet1', data: excelData }], options);
var filePath = './result/notInWord.xlsx';
fs.writeFileSync(filePath, buffer, { flag: 'w' }); //
